home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gsdbloo.exe / DEMOR002.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-29  |  3KB  |  103 lines

  1. program DemoR002;
  2. {------------------------------------------------------------------------------
  3.                          DBase Relational File Linkage
  4.                               Relational Examples
  5.                                  Demo Program
  6.  
  7.        Copyright (c)  Richard F. Griffin
  8.  
  9.        10 February 1992
  10.  
  11.        102 Molded Stone Pl
  12.        Warner Robins, GA  31088
  13.  
  14.        -------------------------------------------------------------
  15.        This unit demonstrates how to link the relationships between
  16.        dBase files for data retrieval based on common fields in two files.
  17.  
  18.        The master file index is on the UNIQUEID field.  This will be used
  19.        to get the master record based on the MASTERID field in the
  20.        transaction record.
  21.  
  22.        The routine will read each transaction and display transaction
  23.        information.  It will then find the correct master record and
  24.        display master information.
  25.  
  26. -------------------------------------------------------------------------------}
  27.  
  28. uses
  29.    CRT,
  30.    GS_Date,
  31.    GS_FileH,
  32.    GS_KeyI,
  33.    GS_Strng,
  34.    GS_dBase,
  35.    GS_dBFld;
  36.  
  37. var
  38.    MstrFile : GS_dBFld_Objt;
  39.    TranFile : GS_dBFld_Objt;
  40.    ftest    : file;
  41.  
  42. begin
  43.    ClrScr;
  44.  
  45.    if not GS_FileExists(ftest, 'DEMOR1MF.DBF') then
  46.    begin
  47.       writeln('File DEMOR1MF.DBF not found.  Run DEMOR001 to create.');
  48.       halt;
  49.    end;
  50.  
  51.    if not GS_FileExists(ftest, 'DEMOR1TF.DBF') then
  52.    begin
  53.       writeln('File DEMOR1TF.DBF not found.  Run DEMOR001 to create.');
  54.       halt;
  55.    end;
  56.  
  57.                        {The 'Real' example starts here}
  58.  
  59.    MstrFile.Init('DEMOR1MF');
  60.    MstrFile.Open;
  61.    MstrFile.Index('DEMOR1ID');
  62.    TranFile.Init('DEMOR1TF');
  63.    TranFile.Open;
  64.    TranFile.GetRec(Top_Record);
  65.    while not (TranFile.File_EOF) and (GS_KeyI_Chr <> #27) do
  66.    begin
  67.       ClrScr;
  68.  
  69.                        {Display transaction information}
  70.  
  71.       Writeln('':34,'TRANSACTION');
  72.       Writeln;
  73.       Writeln('  FULLNAME : ',Strip_Flip(TranFile.StringGet('FULLNAME')));
  74.       Writeln('  TRANDATE : ',GS_Date_View(TranFile.DateGet('TRANDATE')));
  75.       Writeln('    AMOUNT : ',TranFile.FieldGet('AMOUNT'));
  76.       Writeln('   PAYTYPE : ',TranFile.FieldGet('PAYTYPE'));
  77.       Writeln;
  78.       Writeln('':20,'-----------------------------------------');
  79.       Writeln('':37,'MASTER');
  80.       Writeln;
  81.  
  82.                  {Now, go find the master record}
  83.  
  84.       if MstrFile.Find(TranFile.FieldGet('MASTERID')) then
  85.       begin
  86.          Writeln('  LASTNAME : ',MstrFile.FieldGet('LASTNAME'));
  87.          Writeln(' FIRSTNAME : ',MstrFile.FieldGet('FIRSTNAME'));
  88.          Writeln('    STREET : ',MstrFile.FieldGet('STREET'));
  89.          Writeln('   ADDRESS : ',MstrFile.StringGet('CITY'),', ',
  90.                                  MstrFile.FieldGet('STATE'),' ',
  91.                                  MstrFile.FieldGet('ZIP'));
  92.       end
  93.       else writeln('Cannot Find the Master Record!');
  94.  
  95.       Writeln;
  96.       Writeln('Press Any Key to Continue: ') ;
  97.       Writeln('[ESC] Will Terminate the Program');
  98.       WaitForKey;
  99.       TranFile.GetRec(Next_Record);
  100.    end;
  101.    MstrFile.Close;
  102.    TranFile.Close;
  103. end.